package com.menxin.stack;


/**
 * Created by Menx on 2019/3/8.
 */
public class LinkedStack<E> implements Stack<E> {

    private LinkedArray<E> list;

    public LinkedStack(){
        list = new LinkedArray<>();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek(E e) {
        return list.get(0);
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public String toString(){
        StringBuilder buf = new StringBuilder();
        buf.append("LinkedStatck[");
        buf.append(list.toString());
        buf.append("]TOP");
        buf.append(",");
        buf.append(list.getSize());
        return buf.toString();
    }
}
